package javaCode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Created by lxy_920912 on 2017/1/12.
 */
public class LeetCode111 {
    public int minDepth(TreeNode root) {
        if(root == null){
          return  0;
        }
        int[] result= new int[1];
        result[0] = -1;

        findMin(root,0,result);
        return result[0];
    }
    public void findMin(TreeNode root,int depth,int[] result){
        if(root != null){
            depth++;
            if(root.left == null && root.right == null){
                if(result[0] == -1){
                    result[0]= depth;
                    return;
                }else{
                    if(result[0] > depth){
                        result[0] = depth;
                        return;
                    }
                }
            }
            findMin(root.left,depth,result);
            findMin(root.right,depth,result);

        }
    }
}
